<?php
// 应用公共文件

function p($arr){
    echo "<pre>";
    print_r($arr);
    echo "</pre>";
}

/** 获取IP
 * @return array|false|mixed|string
 */
function getIp(){

    if(getenv("HTTP_CLIENT_IP")){
        $ip = getenv("HTTP_CLIENT_IP");
    }else if(getenv("HTTP_X_FORWARDED_FOR")){
        $ip = getenv("HTTP_X_FORWARDED_FOR");
    }else if(getenv("REMOTE_ADDR")){
        $ip = getenv("REMOTE_ADDR");
    }else{
        $ip = $_SERVER["REMOTE_ADDR"];
    }

    return $ip;
}

/** 获取网址头部
 * @return string
 */
function getHttpType(){
    return (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') ? 'https://' : 'http://';
}
